﻿$(document).ready(function () {
    $("#btnAddBackgroundImageConfirm").click(function (e) {
        //upload the image (by submiting the form)
        $("#frmUploadImage").submit();
    });

    //when the form has been finished proccesing (and the iframe is being load)
    $("#UploadIframe").load(function () {
        var imageUrl = $(this).contents().text();
        $("#ThumbnailUrl").val(imageUrl);

        var data = $("#frmAddBackgroundImage").serialize();
        $.validator.unobtrusive.parse($("#frmAddBackgroundImage"));

        if ($("#frmAddBackgroundImage").valid()) {
            if ($("#frmUploadImage [name='file']").val() != "") {
                var mainDialog = updateDialog("תמונת רקע חדשה", "300", "550");

                //Invoke AJAX method to add the Background image to DB
                $.post(pathPrefix + "BackgroundImages/AddBackgroundImage", data, function (result) {
                    closeDialog();

                    BindCategories();
                }, "json");
            }
        }
    });
});